<template>
    <div class="chat-history columnStartStretch scrollbar-style">
        <div class="top">
            <h3>标题占位置</h3>
            <div class="buttion-list">
                <el-button type="primary" round :icon="Plus" class="new-buttion" @click="newConversationClick">
                    新聊天
                </el-button>
            </div>
        </div>


        <!-- 历史对话框数据 -->

        <div class="chat-history-list">
            <div class="title">聊天</div>

            <div v-for="item in conversationHistoryList" :key="item.conversationId" class="item"
                @click="conversationClick(item.conversationId)">
                {{ item.title }}
            </div>
        </div>

        <div class="chat-history-footer"></div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { conversationList } from '../api/chatClient'
import { useRouter } from 'vue-router'
import { Plus, } from '@element-plus/icons-vue'

const emit = defineEmits(['newConversationClick', 'conversationClick'])

interface BizChatConversation {
    conversationId: string,
    title: string,
    createTime: Date,
    updateTime: Date
}

let conversationHistoryList = ref<BizChatConversation[]>([])

const router = useRouter()

function requestConversationList() {
    conversationList().then(res => {
        conversationHistoryList.value = res.data;
    })
}

function newConversationClick() {
    emit("newConversationClick")
}

function conversationClick(conversationId: string) {
    emit("conversationClick", conversationId)
}

onMounted(() => {
    requestConversationList()
})



</script>

<style lang="scss">
.chat-history {
    padding: 0 20px;

    background-color: #ececec;

    font-size: 16px !important;

    height: 100%;
    overflow: auto;



    .init::-webkit-scrollbar-track {
        -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
        border-radius: 10px;
        background-color: #F5F5F5;
    }

    .top {
        margin-bottom: 20px;
        position: sticky;
        top: 0;
        padding: 10px;
        background-color: #ececec;
        border-bottom: 1px solid #e0e0e0;

        .new-buttion {
            font-size: 16px;
            text-align: left;
        }


        .buttion-list {
            margin-top: 30px;
        }
    }


    .new-chat {}

    .chat-history-list {
        margin-top: 30px;
        height: 100%;

        .title {
            width: 100%;
            color: #666;
            font-size: 16px;
            padding: 10px 0;
        }

        .item {
            width: 100%;
            font-size: 18px;
            padding: 10px 5px;
            cursor: pointer;
        }

        .item:hover {
            background-color: #409EFF;
            /* 背景变蓝色 */
            border-radius: 5px;
        }
    }

    .chat-history-footer {
        position: sticky;
        bottom: 0;
        height: 80px;
        width: 100%;
        z-index: 999;
        background-color: #ececec;
        border-top: 1px solid #e0e0e0;
    }
}
</style>